<!DOCTYPE html>
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>
<body>
  
</body>
<script>
  // 1 1 2 3 5 8 13
  function fib(n, a=0, b=1) {
    while (n--) {
      [a, b] = [b, a + b]
    }
    return a
  }

  function fib2(n) {
    if (n < 1) return 1
    return fib2(n - 1) + fib2(n - 2)
  }

  function fib3(n, memory={ '1': 1,'2': 1 }) {
    let m = memory[n]
    return  memory[n] = m ? m : fib3(n - 1, memory) + fib3(n - 2, memory)
  }
  // console.time()
  // console.log(fib(50));
  // console.timeEnd()
  console.time()
  console.log(fib3(5));
  console.timeEnd()
  
</script>
</html>